package com.fan.teamer.process;

import org.apache.log4j.Logger;

import com.fan.teamer.service.TeamerService;

public abstract class ProcExec<R> {

	private static Logger logger = Logger.getLogger("ProcExec");
	private TeamerService teamerService;
	private String errorMessage;

	public TeamerService getTeamerService() {
		return teamerService;
	}

	public void setTeamerService(TeamerService teamerService) {
		this.teamerService = teamerService;
	}

	public void registerProcStart() {
		logger.info("Start process...");
	}

	public void registerProcEnd() {
		logger.info("End process...");
	}

	public static Logger getLogger() {
		return logger;
	}

	public static void setLogger(Logger logger) {
		ProcExec.logger = logger;
	}

	public String getErrorMessage() {
		return errorMessage;
	}

	public void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
		logger.debug(errorMessage);
	}

	public R process() {
		registerProcStart();
		R rc = null;

		try {
			rc = processImpl();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			registerProcEnd();
		}

		return rc;
	}

	public abstract R processImpl();
}
